package com.wangyadong.hobby.schedule.jobtask.dsa;

class MinStack {

    private Integer[] objects;
    private int size = -1;
    private int min;

    /**
     * initialize your data structure here.
     */
    public MinStack() {
        // 在此处写入代码
        objects = new Integer[100];
    }

    public void push(int x) {
        // 在此处写入代码
        size++;
        objects[size] = x;
        if (x < min) {
            min = x;
        }
    }

    public void pop() {
        // 在此处写入代码
        objects[size] = null;
        this.min=0;
        for (Integer object : objects) {
            if (object != null) {
                if (this.min > object) {
                    this.min = object;
                }
            }

        }
        size--;
    }

    public int top() {
        // 在此处写入代码
        return objects[size];
    }

    public int getMin() {
        // 在此处写入代码
        return min;
    }


    /**
     * Your MinStack object will be instantiated and called as such:
     * MinStack obj = new MinStack();
     * obj.push(x);
     * obj.pop();
     * int param_3 = obj.top();
     * int param_4 = obj.getMin();
     */

    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(2);
        minStack.push(-1);
        minStack.push(-3);
        System.out.println(minStack.top() == -3);
        minStack.pop();
        System.out.println(minStack.getMin() == -1);

    }
}